package robot;

import com.ibm.eNetwork.ECL.ECLErr;
import com.ibm.eNetwork.ECL.ECLOIA;
import com.ibm.eNetwork.ECL.ECLPS;
import com.ibm.eNetwork.ECL.ECLSession;
import com.ibm.eNetwork.HOD.customizable.CustomDesktop;
import com.ibm.eNetwork.HOD.customizable.HODDisplaySession;
import com.ibm.eNetwork.HOD.customizable.HODSessionManager;
import com.ibm.eNetwork.beans.HOD.Terminal;
import java.awt.Dimension;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import javax.swing.*;

public class Sample1 extends JFrame {

    JMenuBar menuBar = new JMenuBar();
    CustomDesktop desktop = null;
    HODDisplaySession session = null;
 
    
    
    Terminal terminal = null;
    ECLSession eSession = null;
    ECLPS ps = null;
    ECLOIA oia;
    
    public static void main(String[] args) {
        new Sample1().run();
    }

    private Sample1() {
    }

    void run() {
        HODSessionManager sm = new HODSessionManager();
        /*
         * For this sample, we are assuming files created by the Deployment
         * Wizard are in c:\MyApplication\demo\HODData\sample1 directory
         *
         * Therefore, I need to create a File object to c:\MyApplication\demo
         * directory.
         */

        try {
            File file = new File("C:\\Documents and Settings\\Administrador\\Meus documentos");
            desktop = sm.createCustomDesktop(this, "http://sisbb.bb.com.br/hod/", "sisbb");
        } catch (Exception e) {
        }
        buildMenus();
        setJMenuBar(menuBar);
        if (desktop != null) {
            createTerminal();
        }
        addWindowListener(new WindowAdapter() {

            public void windowClosing(WindowEvent we) {
                myExit();
            }
        });
        Toolkit toolkit = this.getToolkit();
        Dimension screenSize = toolkit.getScreenSize();
        this.setSize(screenSize.width * 2 / 3, screenSize.height * 2 / 3);
        this.setLocation((screenSize.width - getWidth()) / 2, (screenSize.height - getHeight()) / 2);           
        
        this.setVisible(true);
        this.pack();     

        terminal = session.getTerminal();
        eSession = terminal.getECLSession();
        ps = eSession.GetPS();
        oia = eSession.GetOIA();
        //TODO Código aqui abaixo.             
        
    }

    void buildMenus() {

        JMenu menu = new JMenu("File");
        JMenuItem menuItem = new JMenuItem("Exit");
        menu.add(menuItem);
        menuItem.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent ae) {
                myExit();
            }
        });
        menuBar.add(menu);
    }

    void createTerminal() {

        try {
            session = desktop.startDisplaySession("SISBB Intranet");
            if (session != null) {
                this.getContentPane().add(session.getTerminal());

                JMenu menu = new JMenu("HOD Session");
                menuBar.add(menu);

                JMenuBar hodMenuBar = session.getHODMenubar();
                MenuElement[] menuElements = hodMenuBar.getSubElements();
                int count = hodMenuBar.getMenuCount();
                for (int i = 0; i < menuElements.length; i++) {
                    menu.add((JMenu) menuElements[i]);
                }
            }
        } catch (Exception e) {
        }
    }

    void myExit() {
        if (desktop != null) {
            desktop.closeAllSessions();
        }
        System.exit(0);
    }
    
     
}